package com.ruoyi.framework.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author 明一G
 * @date 2023/3/27 17:44
 */
@Component
public class MpMetaObjectHandlerConfig implements MetaObjectHandler {

	/**
	 * 插入时的填充策略
	 * @param metaObject
	 */
	@Override
	public void insertFill(MetaObject metaObject) {
//		this.setFieldValByName("createBy", UserUtil.getUsername(),metaObject);
		this.setFieldValByName("createTime", new Date(), metaObject);
//		this.setFieldValByName("updateBy", UserUtil.getUsername(),metaObject);
		this.setFieldValByName("updateTime", new Date(), metaObject);
	}

	/**
	 * 更新时的填充策略
	 * @param metaObject
	 */
	@Override
	public void updateFill(MetaObject metaObject) {
//		this.setFieldValByName("updateBy", UserUtil.getUsername(),metaObject);
		this.setFieldValByName("updateTime", new Date(), metaObject);
	}
}
